<?php

Yii::import('bootstrap.gii.bootstrap.BootstrapCode');

class CrudBootstrap80Code extends BootstrapCode {

	public function generateActiveRow($modelClass, $column) {
		if ($column->type === 'boolean')
			return "echo \$form->checkBoxRow(\$model, '{$column->name}');";
		else if (stripos($column->dbType, 'text') !== false)
			return "\$htmlOptions = array('rows'=>7, 'cols'=>50, 'class'=>'span8');\necho \$form->textAreaRow(\$model, '{$column->name}', \$htmlOptions);";
		else if (stripos($column->dbType, 'date') !== false) {
			$l = array(
				"\$htmlOptions = array(\n",
				"\t'hint'=>'Use yyyy-mm-dd format',\n",
				"\t'prepend'=>'<i class=\"icon-calendar\"></i>',\n",
				"\t'options'=>array(\n",
				"\t\t'dateFormat'=>'yy-mm-dd',\n",
				"\t\t'changeYear'=>TRUE,\n",
				"\t\t'changeMonth'=>TRUE,\n",
				"\t),\n",
				");\n",
				"echo \$form->datepickerRow(\$model, '{$column->name}', \$htmlOptions);"
			);
			return implode('', $l);
		}
		else {
			if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name))
				$inputField = 'passwordFieldRow';
			else
				$inputField = 'textFieldRow';

			if ($column->type !== 'string' || $column->size === null)
				return "\$htmlOptions = array('class'=>'span5');\necho \$form->{$inputField}(\$model, '{$column->name}', \$htmlOptions);";
			else
				return "\$htmlOptions = array('class'=>'span5', 'maxlength'=>$column->size);\necho \$form->{$inputField}(\$model, '{$column->name}', \$htmlOptions);";
		}
	}

}
